home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / screen / wrtln.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  3.8 KB  |  129 lines

  1. ;void  wrtln(strg,color);
  2. ;  unsigned char  *strg,color;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _video_buffer:word
  6.     EXTRN  _video_page:byte
  7.     EXTRN  _snow_protect:byte
  8.  
  9. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  10.     ASSUME CS:_TEXT
  11.     PUBLIC _wrtln
  12. _wrtln    proc near
  13.     push bp            ;
  14.     mov  bp,sp        ;set stack frame
  15.     push di            ;
  16.     push si            ;
  17.     cmp  _memory_model,0    ;near or far?
  18.     jle  begin        ;jump if near
  19.     inc  bp            ;else add 2 to BP
  20.     inc  bp            ;
  21. begin:    push ds            ;DS changed
  22.     cld            ;direction flag forward
  23.     mov  ax,_video_buffer    ;get video buffer address
  24.     mov  es,ax        ;place in ES
  25.     mov  bh,_video_page    ;set the cursor page
  26.     mov  bl,_snow_protect   ;fetch _snow_protect
  27.     mov  ah,3        ;BIOS func for cursor pos
  28.     int  10h        ;now DH-DL holds row-col
  29.     cmp  _memory_model,2    ;data near or far?
  30.     jb   L0            ;jump if near
  31.     lds  si,dword ptr[bp+4] ;DS:SI pts to Strg
  32.     inc  bp            ;add 2 to BP since dword ptr    
  33.     inc  bp            ;
  34.     jmp  short L00        ;
  35. L0:    mov  si,[bp+4]        ;near case
  36. L00:    mov  [bp+4],bx        ;save _video_page and _snow_protect
  37.     sub  cx,cx        ;clear CX
  38.     push si            ;keep initial pointer position
  39. L000:    cmp  byte ptr[si],0    ;end of string?
  40.     je   L0000        ;jump if so
  41.     inc  si            ;inc ptr 
  42.     inc  cx            ;inc counter
  43.     jmp  short L000        ;loop till end
  44. L0000:    pop  si            ;restore ptr
  45.     mov  ax,160        ;cursor pos: bytes in row
  46.     mul  dh            ;multiply by num rows
  47.     sub  dh,dh        ;now DX holds num cols
  48.     shl  dx,1        ;double for attri bytes
  49.     add  ax,dx        ;cursor offset in buffer
  50.     mov  di,ax        ;now ES:DI pts to pos
  51.     mov  bx,3840        ;scrl if won't fit row 24
  52.     sub  bx,di        ;space left
  53.     mov  ax,cx        ;chars to be printed
  54.     shl  ax,1        ;double for attributes
  55.     or   cx,cx        ;test for null string
  56.     jnz  L1            ;jump if not null
  57.     cmp  di,3840        ;last row?
  58.     jnge L1            ;jump if not
  59.     mov  al,1        ;scroll if null on Row 25
  60.     jmp  short L2        ;jump ahead
  61. L1:    cmp  bx,ax        ;enough room?
  62.     jge  L4            ;jump ahead if so
  63.     sub  ax,bx        ;amount space required
  64.     mov  bl,160        ;bytes in a row
  65.     div  bl            ;divide
  66.     cmp  ah,0        ;any remainder?
  67.     je   L2            ;if not, jump ahead
  68.     inc  al            ;else, scroll 1 more line
  69. L2:    push cx            ;save string length
  70.     push bp            ;scrolling changes BP
  71.     push ax            ;save num lines scrolled
  72.     mov  bh,[bp+6]        ;attribute of new lines
  73.     mov  cx,0000h        ;top left row-col
  74.     mov  dx,184Fh        ;bottom right row-col
  75.     mov  ah,6        ;upwards scroll function
  76.     int  10h        ;make the scroll
  77.     pop  cx            ;num lines scrolled in CL
  78.     sub  ch,ch        ;clear CH, use CX counter
  79. L3:    sub  di,160        ;screen ptr back 1 line
  80.     loop L3            ;repeat for ea ln of scrl
  81.     pop  bp            ;restore BP
  82.     pop  cx            ;restore string length
  83. L4:    or   cx,cx        ;test for null string
  84.     jnz  L5            ;jump if not null
  85.     add  di,160        ;increase screen ptr
  86.     jmp  L10        ;jump and set cursor
  87. L5:    mov  ah,[bp+6]        ;get attribute
  88. L6:    lodsb            ;get a character
  89.     mov  dx,es        ;get video buffer address
  90.     cmp  byte ptr[bp+4],0    ;protect against snow?
  91.     je   L9            ;jump ahead if not
  92.     mov  dx,3dah        ;status byte address
  93.     mov  bx,ax        ;save AX contents
  94. L7:    in   al,dx        ;get status byte
  95.     test al,1        ;test bit
  96.     jnz  L7            ;loop till 0
  97.     cli            ;disable interrupts
  98. L8:    in   al,dx        ;get status byte
  99.     test al,1        ;test bit
  100.     jz   L8            ;loop till 1
  101.     mov  ax,bx        ;char/attri back to AX
  102. L9:    stosw            ;write it with attribute
  103.     loop L6            ;go do next char
  104. L10:    sti            ;reenable interrupts
  105.     mov  ax,di        ;now set new cursor pos
  106.     mov  dl,160        ;chars in a row
  107.     div  dl            ;divide scrn ptr
  108.     shr  ah,1        ;div remainder by 2
  109.     mov  dh,al        ;BIOS: row in DH
  110.     mov  dl,ah        ;col in DL
  111.     cmp  dl,0        ;already at new line?
  112.     je   L11        ;if so, jump ahead
  113.     inc  dh            ;else add 1 more line
  114.     mov  dl,0        ;set cursor to col 0
  115. L11:    mov  bh,[bp+5]        ;page number
  116.     mov  ah,2        ;function number
  117.     int  10h        ;set the cursor
  118.     pop  ds            ;
  119.     pop  si            ;
  120.     pop  di            ;
  121.     pop  bp            ;
  122.     cmp  _memory_model,0    ;quit
  123.     jle  quit        ;
  124.     db   0CBh        ;RET far
  125. quit:    ret            ;RET near
  126. _wrtln   endp
  127. _TEXT    ENDS
  128.     END
  129.